/**
 * 详情对话框
 */
var LiuGoodsInfoDlg = {
    data: {
        brandId: "",
        brandName:"",
        model: "",
        specifications: "",
        unit: "",
        weight: "",
        state: "",
        price: "",
        establish: "",
        remarks: "",
        pid: "",
        pids: ""
    }
};

layui.use(['layer', 'form', 'admin', 'laydate', 'ax'], function () {
   var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var layer = layui.layer;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/liuGoods/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('liuGoodsForm', result.data);

    // 点击商品品牌的时候
    $('#brandId').click(function () {
     var formName = encodeURIComponent("parent.LiuGoodsInfoDlg.data.brandName");
       var formId = encodeURIComponent("parent.LiuGoodsInfoDlg.data.brandId");
        var treeUrl = encodeURIComponent("/liuTree/tree");

        layer.open({
            type: 2,
            title: '商品品牌选择',
            area: ['800px', '400px'],
            content: Feng.ctxPath + '/system/commonTree1?formName='+formName+"&formId=" + formId +"&treeUrl=" + treeUrl,
            end: function () {
                console.log(LiuGoodsInfoDlg.data);
                $("#brandId").val(LiuGoodsInfoDlg.data.brandId);
                $("#brandName").val(LiuGoodsInfoDlg.data.brandName);
            }
        });
    });


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/liuGoods/editItem", function (data) {
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/liuGoods'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/liuGoods'
    });

});